import os

from flask import Flask

import demo_app
import task_app
import settings
import extensions
import commons


def create_app(config_name=None):
    """ app 初始化函数 """
    app = Flask(__name__)
    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'development')

    # app初始化(私)
    app = demo_app.init_app(app, config_name)
    app = task_app.init_app(app, config_name)

    # app初始化(公)
    app.config.from_object(settings.config[config_name])
    extensions.register_extensions(app)
    # 初始化通用信息
    commons.init_common_pre(app)

    return app

app = create_app('development')

if __name__ == '__main__':
    app.run(debug=True)
